home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Admin.aspx.cs655
< prev
next >
Wrap
Text File
|
2008-02-23
|
17KB
|
422 lines
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
/// <summary>
/// Summary description for Admin.
/// </summary>
public partial class Admin : Page
{
protected HtmlInputText mimeType;
private Settings guideParams;
protected void Page_Load(object sender, EventArgs e)
{
//Code to prevent Guest users from accessing the Admin page directly by URL
if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
{
string hostAddress = string.Empty;
string Url =
Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
string redirectUrl = Url.ToLower().Replace("admin.aspx", "guide.aspx");
Logger.Info(" ");
Logger.Info(" ");
Logger.Info("Guest user trying to access the admin page......");
Logger.Info("Pulling User IP Info...");
if (Request.UserHostAddress.Substring(0, 1) == ":")
{
Logger.Info("IP V6 Detected");
hostAddress = GetIP4Address();
Logger.Info("IP6 Address: " + Request.UserHostAddress);
Logger.Info("IP4 Address: " + hostAddress);
Logger.Info(" ");
}
else
{
Logger.Info("IP V4 Detected");
hostAddress = Request.UserHostAddress;
Logger.Info("IP4 Address: " + hostAddress);
Logger.Info(" ");
}
Logger.Info("Redirecting user to the guide");
Logger.Info(" ");
Logger.Info(" ");
Response.Redirect(redirectUrl, true);
}
Session["GuideStartTime"] = null;
if (User.Identity.Name.Length == 0)
{
FormsAuthentication.SignOut();
Response.Redirect("Login.aspx?ReturnUrl=" + HttpUtility.UrlEncode(Request.Url.PathAndQuery));
}
guideParams = Global.Settings;
VLCCommon VLC = new VLCCommon(1);
VLCCommon VLC2 = new VLCCommon(2);
if (!IsPostBack)
{
string[] themes = Directory.GetDirectories(Server.MapPath(Request.ApplicationPath + "/themes/"));
//Create an array to hold the theme names so we can easily sort it later
ArrayList themenames = new ArrayList();
foreach (string theme in themes)
{
//Load each theme that is found in the themes directory to the array of names
if (File.Exists(Path.Combine(theme, "styles.css")))
{
themenames.Add(Path.GetFileName(theme));
}
}
//set the first theme in the list to Default
dropdownThemes.Items.Add("Default");
//Sort the loaded themes into alphabetical order
themenames.Sort();
//Add the sorted themnames to the dropdown list
foreach (string s in themenames)
{
dropdownThemes.Items.Add(s);
}
HttpCookie cookie = Request.Cookies["minuteSpan"];
txtMinuteSpan.Value = cookie != null ? cookie.Value : "120";
cookie = Request.Cookies["minuteInterval"];
txtMinuteInterval.Value = cookie != null ? cookie.Value : "30";
cookie = Request.Cookies["minuteSlice"];
txtMinuteSlice.Value = cookie != null ? cookie.Value : "1";
cookie = Request.Cookies["TimelineRepeat"];
txtTimelineRepeat.Value = cookie != null ? cookie.Value : "10";
guideStartTime.Text = guideParams.guideStartTime;
DateTime now = DateTime.Now;
DateTime then = now.AddMinutes(Convert.ToDouble(guideParams.reminder));
TimeSpan span = then - now;
txtReminderDays.Value = span.Days.ToString();
txtReminderHours.Value = span.Hours.ToString();
txtReminderMinutes.Value = span.Minutes.ToString();
dropdownRecordingQuality.SelectedValue = guideParams.recordingQuality.ToString();
string themeName = Convert.ToString(Session["theme"]);
if (themeName != null && themeName != "")
{
int themeIdx = themeName.IndexOf("/");
if (themeIdx > 0)
{
themeName = themeName.Substring(themeIdx + 1, themeName.Length - (themeIdx + 1));
dropdownThemes.SelectedValue = themeName;
}
else
{
dropdownThemes.SelectedValue = "Default";
}
}
else
{
dropdownThemes.SelectedValue = "Default";
}
displayTabs.Items[0].Selected = guideParams.showTVGuide;
displayTabs.Items[1].Selected = guideParams.showManage;
displayTabs.Items[2].Selected = guideParams.showSearch;
displayTabs.Items[3].Selected = guideParams.showVideoLib;
displayTabs.Items[4].Selected = guideParams.showMusicLib;
displayTabs.Items[5].Selected = guideParams.showPhotoLib;
displayTabs.Items[6].Selected = guideParams.showStats;
showDescription.Checked = guideParams.showDescription;
showDescription.Checked = guideParams.showDescription;
showSubtitle.Checked = guideParams.showSubtitle;
showGenre.SelectedValue = guideParams.showGenre;
showRating.Checked = guideParams.showRating;
showNew.Checked = guideParams.showNew;
showIMDB.Checked = guideParams.showIMDB;
showNetflix.Checked = guideParams.showNetflix;
showTVCom.Checked = guideParams.showTVCom;
showWiki.Checked = guideParams.showWiki;
showCredits.Checked = guideParams.showCredits;
showAirDate.Checked = guideParams.showAirDate;
showStarRating.Checked = guideParams.showStarRating;
showHD.Checked = guideParams.showHD;
playlistExtension.Value = guideParams.playlistExtension;
cookie = Request.Cookies["useChannelIcons"];
UseChannelIcons.SelectedValue = cookie != null ? cookie.Value : "chnlText";
autoShowSearch.SelectedValue = guideParams.autoShowSearch.ToString();
autoRecordSearch.SelectedValue = guideParams.autoShowRecord.ToString();
autoSearchEPGDays.Value = guideParams.autoSearchDays.ToString();
cookie = Request.Cookies["channelIconHeight"];
txtChnlIconH.Value = cookie != null ? cookie.Value : "";
cookie = Request.Cookies["channelIconWidth"];
txtChnlIconW.Value = cookie != null ? cookie.Value : "";
txtAutologinList.Text = guideParams.autologinNetworks;
guestUser.Value = guideParams.GuestUser;
guestPassword.Value = guideParams.GuestPassword;
//Web Streamer Variables
streamPlayer.Text = guideParams.strmPlayer;
externalPlayer.Checked = guideParams.strmExternal;
streamPlayer2.Text = guideParams.strmPlayer2;
externalPlayer2.Checked = guideParams.strmExternal2;
//Web Streamer VLC Common Class
strmVLCLoc.Text = VLC.getVLCLoc();
strmVLCLoc2.Text = VLC2.getVLCLoc();
spanExtendedEWA.Visible = ExtendedEWA.Initialize();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void forceSearch_Click(object sender, EventArgs e)
{
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.autoSearch(searchUtil.loadAutoSearches());
}
protected void Kill_All_Reminders_Click(object sender, EventArgs e)
{
Schedule scheduleHelper = Global.Schedule;
ArrayList reminders = scheduleHelper.GetReminderList();
foreach (Programme programme in reminders)
{
scheduleHelper.RemoveReminder(programme);
}
}
protected void hlSubmit_Click(object sender, EventArgs e)
{
HttpCookie cookie = new HttpCookie("minuteSpan", txtMinuteSpan.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
cookie = new HttpCookie("minuteInterval", txtMinuteInterval.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
cookie = new HttpCookie("minuteSlice", txtMinuteSlice.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
cookie = new HttpCookie("TimelineRepeat", txtTimelineRepeat.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
guideParams.guideStartTime = guideStartTime.Text;
double minutes = 0;
try
{
minutes = ((Convert.ToDouble(txtReminderDays.Value) * 24) * 60);
}
catch
{
minutes = 0;
txtReminderDays.Value = "0";
}
try
{
minutes += (Convert.ToDouble(txtReminderHours.Value) * 60);
}
catch
{
minutes += 0;
txtReminderHours.Value = "0";
}
try
{
minutes += Convert.ToDouble(txtReminderMinutes.Value);
}
catch
{
minutes += 0;
txtReminderMinutes.Value = "0";
}
guideParams.reminder = minutes.ToString();
guideParams.recordingQuality = dropdownRecordingQuality.SelectedValue;
//Save the selected theme to the cookie for future use as well as the Session for current use
cookie = new HttpCookie("theme", dropdownThemes.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
Session["theme"] = "themes/" + dropdownThemes.SelectedValue;
guideParams.showTVGuide = displayTabs.Items[0].Selected;
guideParams.showManage = displayTabs.Items[1].Selected;
guideParams.showSearch = displayTabs.Items[2].Selected;
guideParams.showVideoLib = displayTabs.Items[3].Selected;
guideParams.showMusicLib = displayTabs.Items[4].Selected;
guideParams.showPhotoLib = displayTabs.Items[5].Selected;
guideParams.showStats = displayTabs.Items[6].Selected;
guideParams.showDescription = showDescription.Checked;
guideParams.showSubtitle = showSubtitle.Checked;
guideParams.showGenre = showGenre.SelectedValue;
guideParams.showRating = showRating.Checked;
guideParams.showNew = showNew.Checked;
guideParams.showIMDB = showIMDB.Checked;
guideParams.showNetflix = showNetflix.Checked;
guideParams.showTVCom = showTVCom.Checked;
guideParams.showWiki = showWiki.Checked;
guideParams.showCredits = showCredits.Checked;
guideParams.showAirDate = showAirDate.Checked;
guideParams.showStarRating = showStarRating.Checked;
guideParams.showHD = showHD.Checked;
guideParams.autoShowSearch = Convert.ToBoolean(autoShowSearch.SelectedValue);
guideParams.autoShowRecord = Convert.ToBoolean(autoRecordSearch.SelectedValue);
guideParams.autoSearchDays = Convert.ToDouble(autoSearchEPGDays.Value);
cookie = new HttpCookie("showTVGuide", displayTabs.Items[0].Selected.ToString());
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
cookie = new HttpCookie("useChannelIcons", UseChannelIcons.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
guideParams.playlistExtension = playlistExtension.Value;
cookie = new HttpCookie("channelIconHeight", txtChnlIconH.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
cookie = new HttpCookie("channelIconWidth", txtChnlIconW.Value);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
guideParams.autologinNetworks = txtAutologinList.Text;
guideParams.GuestUser = guestUser.Value;
guideParams.GuestPassword = getMd5Hash(guestPassword.Value);
//Web Streamer
guideParams.strmPlayer = streamPlayer.Text;
guideParams.strmExternal = externalPlayer.Checked;
guideParams.strmVLCLoc = strmVLCLoc.Text;
guideParams.strmPlayer2 = streamPlayer2.Text;
guideParams.strmExternal2 = externalPlayer2.Checked;
guideParams.strmVLCLoc2 = strmVLCLoc2.Text;
Global.Settings.Save();
string[] invalidAutologinNetworks = guideParams.ParseAutologinNetworks();
if (invalidAutologinNetworks.Length > 0)
{
lblAutologinWarning.Text = "WARNING: Invalid ranges: " + string.Join(",", invalidAutologinNetworks);
}
else
{
lblAutologinWarning.Text = string.Empty;
}
Page.RegisterStartupScript("startupScript", "<script language=JavaScript>reload();</script>");
}
static string getMd5Hash(string input)
{
// Create a new instance of the MD5CryptoServiceProvider object.
MD5 md5Hasher = MD5.Create();
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
protected void sizeDefault_Click(object sender, EventArgs e)
{
txtChnlIconH.Value = string.Empty;
txtChnlIconW.Value = string.Empty;
}
protected void hlAutologinInternal_Click(object sender, EventArgs e)
{
txtAutologinList.Text = "127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16";
}
protected void hlAutologinNone_Click(object sender, EventArgs e)
{
txtAutologinList.Text = "none";
}
protected void txtPort_TextChanged(object sender, EventArgs e)
{
}
public string GetIP4Address()
{
string strIP4Address = String.Empty;
foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (objIP.AddressFamily.ToString() == "InterNetwork")
{
strIP4Address = objIP.ToString();
break;
}
}
return strIP4Address;
}
}
}